<?php
  session_start();
    $user = isset($_SESSION["user"])?$_SESSION["user"]:null;
    if(!$user){
        echo "未登录，请先去<a href='login.html'>登录</a>";
    }else{
        $title = $_POST["Title"];
        $content = $_POST["Content"];
        $createTime = (new DateTime())->format('Y-m-d H:i:s');
        $updateTime = $createTime;
        $authorId = $user["id"];
        $authorName = $user["username"];

        $sql = "INSERT INTO `article` 
        (`Title`,`Content`,`CreateTime`,`UpdateTime`,`AuthorId`,`AuthorName`)
        VALUES ('$title','$content','$createTime','$updateTime','$authorId','$authorName')";

        echo $sql;

        $conn =  new mysqli("localhost",'root','',"mybolg");
        $conn -> query($sql);
        if($conn->error) echo $conn->error;
        else echo "新添成功";
    }
?> 